package com.joejag.mavenstats.server.service;

import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import com.joejag.mavenstats.client.dto.ReportDTO;
import com.joejag.mavenstats.client.service.ReportsService;
import com.joejag.mavenstats.server.dao.FakeProjectsDao;
import com.joejag.mavenstats.server.dao.ProjectsDao;
import com.joejag.mavenstats.server.reports.Report;
import com.joejag.mavenstats.server.reports.impls.AllDependenciesReport;
import com.joejag.mavenstats.server.reports.impls.MostUsedDependenciesByGroupingReport;
import com.joejag.mavenstats.server.reports.impls.MostUsedDependenciesByNameReport;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;


public class ReportsServiceImpl extends RemoteServiceServlet implements ReportsService
{
  private ProjectsDao projectsDao;
  private HashMap reports;

  public ReportsServiceImpl()
  {
    projectsDao = FakeProjectsDao.instance();
    reports = new HashMap();

    Report allDependencies = new AllDependenciesReport(projectsDao);
    Report mostUsedDependenciesReportByGrouping = new MostUsedDependenciesByGroupingReport(projectsDao);
    Report mostUsedDependenciesReportByName = new MostUsedDependenciesByNameReport(projectsDao);

    reports.put(allDependencies.getReportName(), allDependencies);
    reports.put(mostUsedDependenciesReportByGrouping.getReportName(), mostUsedDependenciesReportByGrouping);
    reports.put(mostUsedDependenciesReportByName.getReportName(), mostUsedDependenciesReportByName);
  }

  public List getReportNames()
  {
    return new ArrayList(reports.keySet());
  }

  public ReportDTO getReport(String reportName)
  {
    return ((Report) reports.get(reportName)).generateReport();
  }
}